#include "net.h"

void prompt(char* s)
{

	printf("%s ser_ip ser_port\n",s);
}

int main(int argc, char** argv)
{

	int fd;
	struct sockaddr_in soc;

	if(argc !=3)
	{
		prompt(argv[0]);
	}
	//创建套节字
	if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
	{
		perror("socket");
		exit(1);
	}

	//填充
	soc.sin_family = AF_INET;
	soc.sin_port = htons(POTR);
	if( (inet_pton(AF_INET, argv[1], &soc.sin_addr)) != 1)
	{
		perror("inet_pton");
		exit(1);
	}

	if (connect (fd, (struct sockaddr *) &soc, sizeof (soc)) < 0) {
		perror ("connect");
		exit (1);
	}

	printf ("客户端启动成功!\n");

	int ret;
	char buf[BUFSI];
	while(1)
	{
		if((fgets(buf, BUFSI-1, stdin)) == NULL)
		{
			continue;
		}
		do
		{
			ret = write(fd, buf, strlen(buf));
		}
		while(ret < 0 && errno == EINTR);
	}



	return 0;
}



















